package com.ssy.lingxi.logistics.repository;

import com.ssy.lingxi.logistics.entity.Company;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import java.util.List;

/**
 * 物流公司实体仓库
 *
 * @author yzc
 * @version 2.0.0
 * @date 2020/7/10
 */
public interface CompanyRepository extends JpaRepository<Company, Long>, JpaSpecificationExecutor<Company> {

    Page<Company> findAllByMemberIdAndRoleId(Long memberId, Long roleId, Pageable page);

    List<Company> findAllByMemberIdAndRoleIdAndCooperateTypeAndStatus(Long memberId, Long roleId, Integer cooperateType, Integer status);

    List<Company> findByMemberIdAndRoleIdAndCooperateTypeAndNameContains(Long memberId, Long roleId, Integer cooperateType, String name, Sort sort);

    List<Company> findByCooperateTypeAndNameContains(Integer cooperateType, String name, Sort sort);

    List<Company> findAllByMemberIdAndRoleIdAndCooperateType(Long memberId, Long roleId, Integer cooperateType);

    boolean existsByMemberIdAndRoleIdAndCooperateTypeAndCompanyMemberIdAndCompanyRoleId(Long memberId, Long roleId, Integer cooperateType, Long companyMemberId, Long companyRoleId);

    boolean existsByMemberIdAndRoleIdAndCooperateTypeAndCompanyMemberIdAndCompanyRoleIdAndIdNot(Long memberId, Long roleId, Integer cooperateType, Long companyMemberId, Long companyRoleId, Long id);

    boolean existsByMemberIdAndRoleIdAndCooperateTypeAndNameAndCode(Long memberId, Long roleId, Integer cooperateType, String name, String code);

    boolean existsByMemberIdAndRoleIdAndCooperateTypeAndName(Long memberId, Long roleId, Integer cooperateType, String name);

    boolean existsByMemberIdAndRoleIdAndCooperateTypeAndNameAndCodeAndIdNot(Long memberId, Long roleId, Integer cooperateType, String name, String code, Long id);
}